package io.github.maojian.bianrysearch;

import org.junit.Test;

/**
 * @Auther: jian.mao
 * @Date: 2022-06-23 16:20
 * @Description: https://leetcode.cn/problems/valid-perfect-square/
 */
public class Q367 {
    public boolean isPerfectSquare(int num) {
        int left = 0, right = num;
        while (left <= right) {
            int mid = (right - left) / 2 + left;
            long temp = (long) mid * mid;
            if (temp == num) {
                return true;
            } else if (temp > num) {
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        return false;
    }

    @Test
    public void test() {
        System.out.println(isPerfectSquare(2147483647));
    }
}
